﻿using UnityEngine;

namespace Framework.Utils
{
    public static class TransformExtens
    {
        public static RectTransform GetChildRectTransform(this Transform self, int index)
        {
            Transform child = self.GetChild(index);
            if (child == null)
            {
                return null;
            }
            return child.GetComponent<RectTransform>();
        }
        
        public static Transform SetPosition(this Transform self, float x, float y, float z)
        {
            self.position = new Vector3(x,y,z);
            return self;
        }
        
        public static Transform SetLocalPosition(this Transform self, float x, float y, float z)
        {
            self.localPosition = new Vector3(x,y,z);
            return self;
        }

        public static Transform LocalTranslate(this Transform self, Vector3 dir)
        {
            Vector3 locaPos = self.localPosition;
            locaPos += dir;
            self.localPosition = locaPos;
            return self;
        }
        
        public static RectTransform SetAnchoredPosition(this RectTransform self, float x, float y)
        {
            self.anchoredPosition = new Vector2(x, y);
            return self;
        }
        
        public static RectTransform SetLocalPosition(this RectTransform self, float x, float y, float z)
        {
            self.localPosition = new Vector3(x, y, z);
            return self;
        }
    }
}